﻿namespace Admin.NET.Application.Service;

/// <summary>
/// 约血预警
/// </summary>
public class BasYueXueYuJingService : BaseService<BasYueXueYuJing>
{
    public BasYueXueYuJingService(IServiceScopeFactory scopeFactory) : base(scopeFactory)
    {
    }


    /// <summary>
    /// 获取列表
    /// </summary>
    /// <param name="input"></param>
    /// <returns></returns>
    public async Task<SqlSugarPagedList<BasYueXueYuJingOutput>> Page(BaseKeywordPageInput input)
    {
        return await Queryable
           .WhereIF(input.Keyword.HasValue(), it => it.dingXueYiYuan.Contains(input.Keyword))
           .Select<BasYueXueYuJingOutput>()
           .OrderBy(it => it.dingXueYiYuanId)
           .OrderBy(it => it.daLei)
           .ToPagedListAsync(input.Page, input.PageSize);
    }




    /// <summary>
    /// 通过Id获取
    /// </summary>
    public BasYueXueYuJingOutput Get(long id)
    {
        return GetById<BasYueXueYuJingOutput>(id);
    }

    /// <summary>
    /// 新增成功后返回主键
    /// </summary>
    /// <param name="input"></param>
    /// <returns></returns>
    public long Add(BasYueXueYuJingInput input)
    {
        var entity = _rep.Queryable.Where(t => t.dingXueYiYuanId == input.dingXueYiYuanId && t.daLei == input.daLei).First();
        if (entity != null)
        {
            throw Oops.Oh(entity.dingXueYiYuan + "已存在" + entity.daLei + "的预警值设置！");
        }
        return AddWithInput(input);
    }

    /// <summary>
    /// 更新成功后返回true
    /// </summary>
    /// <param name="input"></param>
    /// <returns></returns>
    public bool Update(BasYueXueYuJingInput input)
    {
        return UpdateWithInput(input);
    }

}
